﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TS_XY_Train_Repaire.Main_Base
{
    public partial class Sys_Setting_Station_CameraClsss : DevExpress.XtraEditors.XtraForm
    {
        public Sys_Setting_Station_CameraClsss()
        {
            InitializeComponent();
        }
        public LeverString_SysTreeMainList _tl = new LeverString_SysTreeMainList();//Tree
        public string _LoadType;

        private void Sys_Setting_Station_CameraClsss_Load(object sender, EventArgs e)
        {
            lb_up.Text = "本级分类名称："+_tl.f_name;

            if (_LoadType == "Add")
            {
                lb_up.Text = "上级分类名称：" + _tl.f_name;
                bt_Sure.Text = "新  增";
            }
            else if (_LoadType == "Edit")
            {
                tb_class.Text = _tl.f_name;
                bt_Sure.Text = "修  改";
            }
            else
            {
                tb_class.Text = _tl.f_name;
                tb_class.Enabled = false;
                bt_Sure.Text = "删  除";
            }
        }

        private void bt_Exit_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void bt_Sure_Click(object sender, EventArgs e)
        {
            string strSQL;
            if (_LoadType == "Add")
            {
                if (_tl.f_id=="M-1")
                {
                    strSQL = "insert into TS_S_B_Station_Camera ( f_name,f_level,f_deep,f_type,f_workerid) Values('" + tb_class.Text.Trim() + "','" + _tl.f_level + "'," + _tl.f_deep + ",'0','" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + "') "; 
                }
                else
                {
                string _level = "";
                int _deep = -1;
                _level = _tl.f_level + _tl.f_id + ",";
                _deep = Convert.ToInt32(_tl.f_deep) + 1;
                strSQL = "insert into TS_S_B_Station_Camera ( f_name,f_level,f_deep,f_type,f_workerid) Values('" + tb_class.Text.Trim() + "','" + _level + "'," + _deep + ",'0','" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + "') ";
                }
             }
 
            else if (_LoadType == "Edit")
            {
                strSQL = "update TS_S_B_Station_Camera set [f_name] = '" + tb_class.Text.Trim() + " ' where f_id = " + _tl.f_id+ "";
            }
            else
            {
                strSQL = "update TS_S_B_Station_Camera set f_del= 1 ,f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_id = " + _tl.f_id + "";
                strSQL += "update TS_S_B_Station_Camera set f_del=1,f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_level like '%," + _tl.f_id + ",%' and f_del=0";
            }
            TS_Win_Class.MySqlCom(strSQL);
            this.DialogResult = DialogResult.OK;
        }
    }
}